{extend name="common/base_page" /}

{block name="title"}数据导入{/block}

{block name="jscssfile"}{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
.l-box{
    width:80%;margin:0 auto;
    border:1px solid #dddddd;
    text-align: center;
    padding:40px 0;
}
.l-box h4{
    font-size:16px;
}
.l-box .l-box-btn{
    margin-top:30px;
}
.layui-row{
    margin-top:40px;
}
.bottom-tip{padding:0 20px 0 20px;}
.ipt-file-hide{display: none;}
</style>
{/block}

{block name="body"}
<div style="width:100%;height:20px;display: block;">&nbsp;</div>
<fieldset class="layui-elem-field layui-field-title" style="margin:0;"> <legend>系统基础数据导入</legend></fieldset>
<div class="layui-row">
    <div class="layui-col-sm3">
        <div class="l-box">
            <h4>患者信息导入</h4>
            <div class="l-box-btn">
                <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="downTpl('hzxx');">1.下载模板</a>
                &nbsp;&nbsp;
                <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="uploadTpl('hzxx');">2.上传数据</a>
            </div>
        </div>
    </div>
    <div class="layui-col-sm3">
        <div class="l-box">
            <h4>西药信息导入</h4>
            <div class="l-box-btn">
                <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="downTpl('xy');">1.下载模板</a>
                &nbsp;&nbsp;
                <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="uploadTpl('xy');">2.上传数据</a>
            </div>
        </div>
    </div>
    <div class="layui-col-sm3">
        <div class="l-box">
            <h4>中药信息导入</h4>
            <div class="l-box-btn">
                <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="downTpl('zy');">1.下载模板</a>
                &nbsp;&nbsp;
                <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="uploadTpl('zy');">2.上传数据</a>
            </div>
        </div>
    </div>
    <div class="layui-col-sm3">
        <div class="l-box">
            <h4>材料信息导入</h4>
            <div class="l-box-btn">
                <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="downTpl('cl');">1.下载模板</a>
                &nbsp;&nbsp;
                <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="uploadTpl('cl');">2.上传数据</a>
            </div>
        </div>
    </div>
</div>

<div class="layui-row">
    <div class="layui-col-sm3">
        <div class="l-box">
            <h4>诊疗项目导入</h4>
            <div class="l-box-btn">
                <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="downTpl('zlxm');">1.下载模板</a>
                &nbsp;&nbsp;
                <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="uploadTpl('zlxm');">2.上传数据</a>
            </div>
        </div>
    </div>
    <div class="layui-col-sm3">
        <div class="l-box">
            <h4>组合项目导入</h4>
            <div class="l-box-btn">
                <a class="layui-btn layui-btn-primary layui-btn-sm" onclick="downTpl('zhxm');">1.下载模板</a>
                &nbsp;&nbsp;
                <a class="layui-btn layui-btn-sm layui-btn-normal" onclick="uploadTpl('zhxm');">2.上传数据</a>
            </div>
        </div>
    </div>
</div>

<div class="layui-row">
    <div class="layui-col-sm12 bottom-tip">
        <blockquote class="layui-elem-quote layui-text">
            <a>第一步：</a>下载相关模板，按照模板格式填写数据。
            <a>第二步：</a>上传已经填写好的数据表格模板。
        </blockquote>
    </div>
</div>
{/block}

{block name="script"}
<script src="__STATIC__/ajaxfileupload.js?v={$site.version}"></script>
<script type="text/javascript">
var cfg = '{$tpl_cfg|raw}';
$(function(){
    setTimeout(function(){
        cfg = $.parseJSON(cfg);
    },50);
});
//下载模板
function downTpl(_tag)
{
    _tag = _tag || '';
    if(_tag == '' || _tag.length <= 0) return false;
    var _obj = cfg[_tag];
    if(typeof(_obj) != 'object') return false;
    window.location.href = '{$site.weburl}/excel_tpl/' + _obj.excel_tpl_filename;
}
//上传数据
function uploadTpl(_tag)
{
    _tag = _tag || '';
    if(_tag == '' || _tag.length <= 0) return false;
    var _obj = cfg[_tag];
    if(typeof(_obj) != 'object') return false;
    var _imgHtml = '<input type="file" accept="application/vnd.ms-excel,xls" name="img_file" id="img_more_file" class="ipt-file-hide">';
    if($('#img_more_file').length) $('#img_more_file').remove();
    $('body').append(_imgHtml);
    $('#img_more_file').on('change',function(b){
        if($(this).val() != '')
        {
            AjaxUploadFile({
                cfg:_obj,
                tag:_tag,
                savedir:'exceltpl_' + _tag,
                inputname:$(this).attr('name'),
                imgid:$(this).attr('id')
            });
        }
    });
    $('#img_more_file').trigger('click');
}
//多图上传-上传动作
function AjaxUploadFile(param)
{
    __showLoadingBox('上传中，请稍候...');
    $.ajaxFileUpload({
        url: "{:url('index/index/upload_excel')}", //用于文件上传的服务器端请求地址
        secureuri: false, //是否需要安全协议，一般设置为false
        fileElementId: param.imgid, //文件上传域的ID
        data:param, //要上传参数
        dataType:"json", //返回值类型 一般设置为json
        success: function(data)  //服务器成功响应处理函数
        {
            if($('#img_more_file').length) $('#img_more_file').remove();
            __hideLoadingBox();
            if(data.err == 0)
            {
                importAction(param.cfg.import_url,{tag:param.tag,path:encodeURIComponent(data.path)});
            }else{
                layer.msg(data.msg, {time: 2000,anim: 6});
            }
        },
        error: function (data, status, e)//服务器响应失败处理函数
        {
            __hideLoadingBox();
            layer.msg('上传出错：' + e, {time: 2000,anim: 6,shade:[0.4,'#000000']});
            return false;
        }
    });
}
//执行导入
function importAction(_url,_param)
{
    _Index.ajax(_url,_param,function(d){
        if(d.err == 0)
        {
            layer.msg(d.msg, {time: 1000},function(){ });
        }else{
           layer.msg(d.msg, {time: 2000,anim: 4});
        }
    },'导入中，请稍候...');
}
</script>
{/block}